<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT  	reserve.id,
												production.`code`,
												production.`name` AS `name`,
												production_category.`name`,
												model.`name`,
												production.`engine`,
												production.engine_capacity,
												production.born_date,
												production.size,
												brand.`name`,
												production.barcode,
												CONCAT(ROUND(SUM(reserve.quantity - reserve.sold), 2),' ', production_unit.`name`) as quantity,
												ROUND(reserve.price , 2) AS cost,
												ROUND((reserve.price * SUM( reserve.quantity - reserve.sold )) , 2) AS sumCost
									FROM  		reserve
    	    		
									LEFT JOIN	object				ON	reserve.object_id = object.id
									LEFT JOIN   production			ON	reserve.production_id = production.id
									LEFT JOIN   production_category ON production_category.id = production.category
									LEFT JOIN   production_unit		ON	production.unit = production_unit.id
									LEFT JOIN   brand 				ON brand.id=production.brand_id
									LEFT JOIN   model 				ON model.id=production.model
    	    		
									WHERE		reserve.quantity - reserve.sold != 0 && ISNULL(reserve.barcode) AND production.actived=1
									GROUP BY  	reserve.object_id, reserve.production_id    			                            
																");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>